import dayjs from "dayjs";
import "dayjs/locale/zh-cn";
dayjs.locale("zh-cn");

const formatTime = (time) => {
    if (!time) return "-";
    try {
        if (time.indexOf("-") > -1) return time;
    }catch(err) {}

    if(typeof time !== 'number' && time.length === 12) {
        let _time =
            time.substring(0, 4) +
            "-" +
            time.substring(4, 6) +
            "-" +
            time.substring(6, 8) +
            " " +
            time.substring(8, 10) +
            ":" +
            time.substring(10, 12);
        return _time;
    }

    if(typeof time === 'number') {
        time = time.toString()
    }

    if (time.length == 10)
        return dayjs(time * 1000).format("YYYY-MM-DD HH:mm");
    if (time.length === 13 || time.length === 12) return dayjs(time * 1).format("YYYY-MM-DD HH:mm");
    if (time.length === 8) return dayjs(time).format("YYYY年MM月DD日");
    if (time.length === 14) {
        let _time =
            time.substring(0, 4) +
            "-" +
            time.substring(4, 6) +
            "-" +
            time.substring(6, 8) +
            " " +
            time.substring(8, 10) +
            ":" +
            time.substring(10, 12);
        return _time;
    }
    if(time.length === 6) {
        let _time =
            time.substring(0, 2) +
            ":" +
            time.substring(2, 4) +
            ":" +
            time.substring(4, 5)
        return _time;
    }
    return time;
};

export default formatTime;
